package offer;

import java.util.ArrayList;
import java.util.List;

public class Solution45 {
    public String minNumber(int[] nums) {
        List<Integer> list = new ArrayList<>();
        for (int num : nums) {
            list.add(num);
        }
        list.sort(((o1, o2) -> {
            if (o1.equals(o2)) {
                return 0;
            }
            char[] a = o1.toString().toCharArray();
            char[] b = o2.toString().toCharArray();
            int i = 0;
            while (i < a.length + b.length) {
                char ai = i < a.length ? a[i] : b[i - a.length];
                char bi = i < b.length ? b[i] : a[i - b.length];
                if (ai < bi) {
                    return -1;
                } else if (ai > bi) {
                    return 1;
                }
                i++;
            }
            return 1;
        }));
        StringBuilder s = new StringBuilder();
        for (Integer i : list) {
            s.append(i);
        }
        return s.toString();
    }
}
